home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / libs / graphics3d.lha / src / library / graphics3Dli.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-20  |  6.5 KB  |  226 lines

  1. /*
  2. **      $VER: LibInit.c 37.16 (23.8.97)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <exec/execbase.h>
  14. #include <exec/resident.h>
  15. #include <exec/initializers.h>
  16.  
  17. #include <proto/exec.h>
  18.  
  19. #include "graphics3Dbase.h"
  20.  
  21. ULONG L_OpenLibs(void);
  22. void  L_CloseLibs(void);
  23.  
  24. extern struct Graphics3DBase *Graphics3DBase;
  25.  
  26.  
  27. struct ExecBase      *SysBase              = NULL;
  28. struct IntuitionBase *IntuitionBase        = NULL;
  29. struct GfxBase       *GfxBase               = NULL;
  30. struct LayersBase    *LayersBase           = NULL;
  31. struct MathIEEEBase  *MathIeeeDoubBasBase  = NULL;
  32. struct MathIEEEBase  *MathIeeeSingBasBase  = NULL;
  33.  
  34. #ifdef DEBUG
  35. struct DOSBase         *DOSBase              = NULL;
  36. #endif
  37.  
  38. #define VERSION  13
  39. #define REVISION 01 
  40.  
  41. char ExLibName [] = "graphics3D.library";
  42. char ExLibID   [] = "graphics3D 13.01 (21.10.98)";
  43. char Copyright [] = "(C)opyright 1996-98 by Patrizio Biancalani & Andreas R. Kleinert . All rights reserved.";
  44.  
  45.  
  46. /* -------------------------------------------------------------------------
  47.  ! ROMTag and Library inilitalization structure:
  48.  !
  49.  ! Below you find the ROMTag, which is the most important "magic" part 
  50.  ! of a library (as for any other resident module). You should not need 
  51.  ! to modify any of the structures directly, since all the data is 
  52.  ! referenced from constants from somewhere else.
  53.  !
  54.  ! You may place the ROMTag directly after the LibStart (-> StartUp.c) 
  55.  ! function as well.
  56.  !
  57.  ! Note, that the data initialization structure may be somewhat redundantit's
  58.  ! for demonstration purposes.
  59.  !
  60.  ! EndResident can be placed somewhere else - but it must follow the ROMTag 
  61.  ! and it must not be placed in a different SECTION.
  62.  ------------------------------------------------------------------------ */
  63.  
  64. extern ULONG InitTab[];
  65. extern APTR EndResident; /* below */
  66.  
  67. struct Resident ROMTag =     /* do not change */
  68. {
  69.  RTC_MATCHWORD,
  70.  &ROMTag,
  71.  &EndResident,
  72.  RTF_AUTOINIT,
  73.  VERSION,
  74.  NT_LIBRARY,
  75.  0,
  76.  &ExLibName[0],
  77.  &ExLibID[0],
  78.  &InitTab[0]
  79. };
  80.  
  81. APTR EndResident;
  82.  
  83. struct MyDataInit                      /* do not change */
  84. {
  85.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  86.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  87.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  88.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  89.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  90.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  91.  ULONG ENDMARK;
  92. } DataTab =
  93. #ifdef VBCC
  94. {
  95.     0xe000,8,NT_LIBRARY, 
  96.     0x0080,10,(ULONG) &ExLibName[0], 
  97.     0xe000,LIBF_SUMUSED|LIBF_CHANGED, 
  98.     0xd000,20,VERSION, 
  99.     0xd000,22,REVISION, 
  100.     0x80,24,(ULONG) &ExLibID[0], 
  101.     (ULONG) 0
  102. };
  103. #else
  104. {
  105.  INITBYTE(OFFSET1(Node,         ln_Type),      NT_LIBRARY),
  106.  0x80, (UBYTE) OFFSET1(Node,    ln_Name),      (ULONG) &ExLibName[0],
  107.  INITBYTE(OFFSET1(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  108.  INITWORD(OFFSET1(Library,      lib_Version),  VERSION),
  109.  INITWORD(OFFSET1(Library,      lib_Revision), REVISION),
  110.  0x80, (UBYTE) OFFSET1(Library, lib_IdString), (ULONG) &ExLibID[0],
  111.  (ULONG) 0
  112. };
  113. #endif
  114.  
  115. /*--------------------------------------------------------------------------
  116.  ! L_OpenLibs:
  117.  !
  118.  ! Since this one is called by InitLib, libraries not shareable between 
  119.  ! Processes or libraries messing with RamLib (deadlock and crash) may not 
  120.  ! be opened here.
  121.  !
  122.  ! You may bypass this by calling this function fromout LibOpen, but then 
  123.  ! you will have to a) protect it by a semaphore and b) make sure, that 
  124.  ! libraries are only opened once (when using globa library bases).
  125.  ------------------------------------------------------------------------ */
  126.  
  127. ULONG L_OpenLibs(void)
  128. {
  129.  SysBase = (*((struct ExecBase **) 4));
  130.  
  131.  IntuitionBase =
  132.     (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  133.  if(!IntuitionBase) return(FALSE);
  134.  
  135.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  136.  if(!GfxBase) 
  137.     {
  138.     CloseLibrary(IntuitionBase);
  139.     return(FALSE);
  140.     }
  141.  
  142.  LayersBase = (struct LayersBase *) OpenLibrary("layers.library", 37);
  143.  if(!LayersBase) 
  144.     {
  145.     CloseLibrary(IntuitionBase);
  146.     CloseLibrary(GfxBase);
  147.     return(FALSE);
  148.     }
  149.  
  150.  MathIeeeSingBasBase=
  151.     (struct MathIeeeSingBasBase *)
  152.     OpenLibrary("mathieeesingbas.library",37);
  153.  if(!MathIeeeSingBasBase) 
  154.     {
  155.     CloseLibrary(IntuitionBase);
  156.     CloseLibrary(GfxBase);
  157.     CloseLibrary(LayersBase);
  158.     return(FALSE);
  159.     }
  160.  
  161.  MathIeeeDoubBasBase=
  162.     (struct MathIeeeDoubBasBase *)
  163.     OpenLibrary("mathieeedoubbas.library",37);
  164.  if(!MathIeeeDoubBasBase) 
  165.     {
  166.     CloseLibrary(IntuitionBase);
  167.     CloseLibrary(GfxBase);
  168.     CloseLibrary(LayersBase);
  169.     CloseLibrary(MathIeeeSingBasBase);
  170.     return(FALSE);
  171.     }
  172.  
  173. #ifdef DEBUG
  174.  DOSBase = (struct DOSBase *) OpenLibrary("dos.library", 37);
  175.  if(!DOSBase) 
  176.     {
  177.     CloseLibrary(IntuitionBase);
  178.     CloseLibrary(GfxBase);
  179.     CloseLibrary(LayersBase);
  180.     CloseLibrary(MathIeeeSingBasBase);
  181.     CloseLibrary(MathIeeeDoubBasBase);
  182.     return(FALSE);
  183.     }
  184. #endif
  185.  
  186.  Graphics3DBase->exb_SysBase       = SysBase;
  187.  
  188.  Graphics3DBase->exb_IntuitionBase        = IntuitionBase;
  189.  Graphics3DBase->exb_GfxBase              = GfxBase;
  190.  Graphics3DBase->exb_LayersBase           = LayersBase;
  191.  Graphics3DBase->exb_MathIeeeDoubBasBase  = MathIeeeDoubBasBase;
  192.  Graphics3DBase->exb_MathIeeeSingBasBase  = MathIeeeSingBasBase;
  193.  
  194. #ifdef DEBUG
  195.  Graphics3DBase->exb_DOSBase       = DOSBase;
  196. #endif
  197.  
  198.  return(TRUE);
  199. }
  200.  
  201. /* -------------------------------------------------------------------------
  202.  ! L_CloseLibs:
  203.  !
  204.  ! This one by default is called by ExpungeLib, which only can take place 
  205.  ! once and thus per definition is single-threaded.
  206.  !
  207.  ! When calling this fromout LibClose instead, you will have to protect it 
  208.  ! by a semaphore, since you don't know whether a given CloseLibrary(foobase)
  209.  ! may cause a Wait().
  210.  ! Additionally, there should be protection, that a library won't be closed 
  211.  ! twice.
  212.  ------------------------------------------------------------------------ */
  213.  
  214. void L_CloseLibs(void)
  215. {
  216. #ifdef DEBUG
  217.  if(DOSBase) CloseLibrary((struct Library *) DOSBase);
  218. #endif
  219.  
  220.  if(MathIeeeDoubBasBase) CloseLibrary((struct Library *)MathIeeeDoubBasBase);
  221.  if(MathIeeeSingBasBase) CloseLibrary((struct Library *)MathIeeeSingBasBase);
  222.  if(LayersBase) CloseLibrary((struct Library *) LayersBase);
  223.  if(GfxBase)       CloseLibrary((struct Library *) GfxBase);
  224.  if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  225. }
  226.